package Offer.offer2018;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 两个队列实现栈
 * Created by 雷文康 on 2018/3/3.
 */
public class Test07a {
    Queue<Integer> list1 = new LinkedList<>();
    Queue<Integer> list2 = new LinkedList<>();


    public void add(int value) {
        if (!list2.isEmpty()) {
            list2.add(value);
        } else {
            list1.add(value);
        }
    }

    public int remove() {
        if (!list1.isEmpty()) {
            while (list1.size() > 1) {
                list2.add(list1.remove());
            }
            return list1.remove();
        } else if (!list2.isEmpty()){
            while (list2.size() > 1) {
                list1.add(list2.remove());
            }
            return list2.remove();
        } else {
            System.out.println("empty");
            return -1;
        }
    }
}
